package com.googlecode.androidutils;

/**
 * Provides some utilities for validating method arguments.
 * 
 * @author Alexander Metzner
 */
public final class ArgumentUtils {

	private ArgumentUtils() {
		// Use static methods
	}

	/**
	 * Asserts that the given string is neither <code>null</code> nor has a
	 * length of zero.
	 * 
	 * @param argumentName
	 *            the name of the method argument
	 * @param value
	 *            the value to check
	 * @return the given value if it is neither <code>null</code> nor empty
	 * @throws IllegalArgumentException
	 *             in case the given string is <code>null</code> or empty
	 */
	public static String notEmpty(final String argumentName, final String value) {
		if (value == null || value.length() == 0) {
			throw new IllegalArgumentException(argumentName
					+ " must not be empty.");
		}
		return value;
	}

	/**
	 * Asserts that the given value is not <code>null</code>.
	 * 
	 * @param <T>
	 *            the type of the value to check
	 * @param argumentName
	 *            the name of the argument
	 * @param value
	 *            the value of the argument
	 * @return the value if it is not <code>null</code>
	 * @throws IllegalArgumentException
	 *             if the value is <code>null</code>
	 */
	public static <T> T notNull(final String argumentName, final T value) {
		if (value == null) {
			throw new IllegalArgumentException(argumentName
					+ " must not be null.");
		}
		return value;
	}

}
